use std::collections::BinaryHeap;
use wasm_bindgen::closure::Closure;
use wasm_bindgen::JsValue;
use wasm_bindgen::prelude::wasm_bindgen;
use crate::CallBack;

#[wasm_bindgen]
// 定义一个全局的原子计数器
// 任务等级

pub enum PriorityLevel {
    NoPriority,
    ImmediatePriority,
    UserBlockingPriority,
    NormalPriority,
    LowPriority,
    IdlePriority
}
impl PriorityLevel {
    // 实现一个方法来返回枚举变体对应的整数值
    pub fn get_timeout(&self) -> i64 {
        match self {
            PriorityLevel::NoPriority => 0,
            PriorityLevel::ImmediatePriority => -1,
            PriorityLevel::UserBlockingPriority => 250,
            PriorityLevel::NormalPriority => 5000,
            PriorityLevel::LowPriority => 10000,
            PriorityLevel::IdlePriority => 1073741823,
        }
    }
}
// 任务的基本类型
pub struct Task {
    pub id: isize,
    pub callback: CallBack,
    pub priority: i16,
    pub start_time: i64,
    pub expiration_time: i64,
    pub sort_index: i64
}
// 实现 PartialEq 特征
impl PartialEq for Task {
    fn eq(&self, other: &Self) -> bool {
        self.priority == other.priority
    }
}

// 实现 Eq 特征
impl Eq for Task {}
// 实现 Ord, PartialOrd, Eq, 和 PartialEq 来定义 Task 的排序规则
impl Ord for Task {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        other.priority.cmp(&self.priority) // 注意这里是反向比较
    }
}
impl PartialOrd for Task {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cmp(other))
    }
}